﻿@{
    var grid = Html.DevExpress().GridView(
        settings => {
            settings.Name = "grid";
            settings.CallbackRouteValues = new { Controller = "Accessibility", Action = "CompliancePartial" };
            settings.Width = Unit.Percentage(100);
            settings.AccessibilityCompliant = (bool)Session["EnableAccessibilityCompliant"];
            settings.Caption = "Employee";
            settings.SummaryText = "This table lists employees of the Northwind company.";

            settings.KeyFieldName = "EmployeeID";
            settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Accessibility", Action = "ComplianceUpdatePartial" };
            
            settings.CommandColumn.VisibleIndex = 0;
            settings.CommandColumn.Width = Unit.Percentage(1);
            settings.CommandColumn.ShowEditButton = true;
            settings.Columns.Add("LastName");
            settings.Columns.Add("FirstName");
            settings.Columns.Add("BirthDate");
            settings.Columns.Add(column => {
                column.FieldName = "ReportsTo";
                column.ColumnType = MVCxGridViewColumnType.ComboBox;
                
                var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                comboBoxProperties.DataSource = Model;
                comboBoxProperties.TextField = "LastName";
                comboBoxProperties.ValueField = "EmployeeID";
                comboBoxProperties.ValueType = typeof(int?);
                comboBoxProperties.IncrementalFilteringMode = IncrementalFilteringMode.StartsWith;
                comboBoxProperties.DropDownStyle = DropDownStyle.DropDownList;
            });
            settings.Columns.Add(column => {
                column.FieldName = "Notes";
                column.ColumnType = MVCxGridViewColumnType.Memo;
                column.Visible = false;
                column.EditFormSettings.ColumnSpan = 2;
                column.EditFormSettings.Visible = DefaultBoolean.True;
                (column.PropertiesEdit as MemoProperties).Height = 60;    
            });

            settings.SettingsDetail.ShowDetailRow = true;
            settings.SetDetailRowTemplateContent(c => { ViewContext.Writer.Write(DataBinder.Eval(c.DataItem, "Notes")); });
            settings.SettingsPager.PageSize = 7;
    });
    
    if(ViewData["EditError"] != null) {
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()